"""
判断是否平稳（为什么spei没有季节性？？？amazing！！！）
"""

from pandas import read_csv
from statsmodels.tsa.stattools import adfuller
from matplotlib import pyplot
series = read_csv(
        'E:\lyf_ML_Drought\coding\ML_Drought_Prediction\indices_caculate\\result\ROW_SPEI\ROW_SPEI-12\SPEI-12_52533.txt',
        header=None, names=('TIME', 'SPEI-12'))
series = series.set_index(['TIME'], drop=True)  # 把日期作为索引
series.hist()
pyplot.show()
X = series.values
result = adfuller(X)
print('ADF Statistic: %f' % result[0])
print('p-value: %f' % result[1])
print('Critical Values:')
for key, value in result[4].items():
	print('\t%s: %.3f' % (key, value))


# example of a difference transform

# # difference dataset
# def difference(data, interval):
# 	return [data[i] - data[i - interval] for i in range(interval, len(data))]
#
# # invert difference
# def invert_difference(orig_data, diff_data, interval):
# 	return [diff_data[i-interval] + orig_data[i-interval] for i in range(interval, len(orig_data))]
#
# # define dataset
# data = [x for x in range(1, 10)]
# print(data)
# # difference transform
# transformed = difference(data, 1)
# print(transformed)
# # invert difference
# inverted = invert_difference(data, transformed, 1)
# print(inverted)